package com.kzd.gtgame.main.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.fragment.app.Fragment
import com.kzd.gtgame.R
import com.kzd.gtgame.entity.PlatformMoney
import com.module.lemlin.image.loadImage
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AlphaConfig
import razerdp.util.animation.AnimationHelper


class ServiceCodePopup(
    context: Context, val onClick: (view: View, type: Int) -> Unit,
) :
    BasePopupWindow(context) {

    init {
        popupGravity = Gravity.CENTER
        setOverlayNavigationBar(false)
    }


    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_service_code)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)

        contentView.findViewById<TextView>(R.id.tvServiceQrCodeCancel)
            .setOnClickListener {
                dismiss()
            }

        contentView.findViewById<TextView>(R.id.tvServiceQrCodeDown)
            .setOnClickListener {
                onClick(it, mType)
            }
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.IN)
            .toShow()
    }

    override fun onCreateDismissAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.OUT)
            .toDismiss()
    }

    private var mType: Int = 0

    fun setContent(resId: Any, type: Int): ServiceCodePopup {
        contentView.findViewById<ImageView>(R.id.ivServiceQrCodeImage)
            .loadImage(resId)
        this.mType = type
        return this
    }

}